<template>
	<view class="contents" :style="'height:'+screenHeight+'px'">
		<view class="none" v-if="showlist==true">
			<view class="">
				<view class="" v-for="(item,index) in Mymedical" :key="index">
					<view class="list">
						<view class="leftlist">
							<view class="lefttop">
								<span>{{item.TJName}}</span>
								<view class="" style="margin-left: 30rpx;">
									<view class="anniu bacnone2" v-if="item.IsDefault==1" type="primary">默认</view>
									<view v-else class="anniuelse color1" @click="adddefault(item.PatientId)">默认</view>
								</view>
							</view>
							<view class="leftbutton">
								<view class="color1" style="margin-top: 10rpx;">
									<u-icon name="phone-fill" size="20"></u-icon>
								</view>
								<span style="float: left;">{{item.TJPhoneNo}}</span>
							</view>
						</view>

						<view class="rightlist">
							<!-- <span class="delete" @click="deletes(item.PatientId)">选择</span> -->
							<span class="delete" @click="deletes(item.TJChildId)">删除</span>
							<span class="delete" @click="xiugai(item.TJChildId)">修改</span>
						</view>

					</view>

				</view>
			</view>
		</view>

		<view class="none" v-else>
			<view class="coent">
				<u-empty text="暂无体检人员" mode="list" icon-size="200">
				</u-empty>
			</view>
		</view>
		<view class="bottom-button">
			<view class="button bacnone2" @click="visit">添加体检人员</view>
		</view>
		<u-modal v-model="showdfault" confirm-color='#3B71E8' :content="contentdfault" show-cancel-button="true"
			@confirm="adddfs" @cancel="removedefault" mask-close-able="true"></u-modal>
		<u-modal v-model="deleteshow" confirm-color='#3B71E8' :content="content" show-cancel-button="true"
			@confirm="confirm" @cancel="deleteshow==false" mask-close-able="true"></u-modal>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex'

	export default {
		data() {
			return {
				screenHeight: getApp().globalData.screenHeight - 44,
				showdfault: false,
				deleteshow: false,
				titlefault: '设置默认就诊人',
				contentdfault: '确认切换默认就诊人吗',
				title: '删除就诊卡',
				content: '删除之后不可恢复，是否确认',
				showlist: false,
				show: false,
				remove: true,
				addshow: false,
				Mymedical: [],
				list: {
					type: 'default',
					message: "删除成功",
				},
				add: {
					type: 'default',
					message: "切换成功",
				},
				list2: {
					type: 'default',
					message: "删除失败",
				},
				doctor: [],
				PatientId: '',
				doctorinfor: '',
				doctlist: []
			}
		},
		created() {

		},
		onLoad: function(doctorinfor) {
			//console.log("doctorinfor.doctorinfor",doctorinfor.doctorinfor)
			if (doctorinfor.doctorinfor == "false" || doctorinfor.doctorinfor == undefined) {
				this.addshow = false
			} else {
				this.addshow = true
				this.remove = false
				this.doctorinfor = doctorinfor.doctorinfor
				this.doctlist = doctorinfor.doctlist
				//console.log("doctlist",doctorinfor.doctlist)
			}
		},
		computed: {
			...mapState(['token'], ['userInfo']),
			...mapGetters(['hasLogin', 'getUserInfo'])
		},
		onShow() {
			if (this.hasLogin) {
				uni.showLoading({
					title: '加载中'
				})
				this.$store.dispatch('getUserInfo');
				this.getlist()
			} else {
				uni.hideLoading();
				uni.showModal({
					title: '提示',
					content: '登录后才可以操作',
					confirmText: '去登录',
					showCancel: false,
					success: function(res) {
						uni.reLaunch({
							url: '/pages/auth/login'
						})
					}
				});
				return;
			}

		},
		methods: {
			xiugai(PatientId) {
				console.log("PatientId",PatientId)
				uni.navigateTo({
					url: `/pages/block/addVisit/addVisitcopyxg?PatientId=${PatientId}`,
					fail(error) {
						console.log(error)
					}
				})
				
				// this.deleteshow = true
				// this.PatientId = PatientId
				// console.log(PatientId)
			},
			adddfs() {
				//console.log("PatientId",this.PatientId)
				uni.showLoading({
					title: '正在切换'
				})
				this.$request("hispatient", "setdefault", {
					PatientId: this.PatientId
				}).then(res => {
					if (res.code == 1) {
						this.showdfault = false
						this.getlist()
						uni.hideLoading();
						// this.showToast(this.add)
					}
				})
			},
			removedefault() {
				this.PatientId = ''
				this.showdfault = false
			},
			adddefault(PatientId) {
				this.PatientId = PatientId
				this.showdfault = true
			},
			getlist() {
				this.$request('TJChildBase', 'list', {
					page: 1,
					rows: 10,
					ChildId: 'all'
				}).then(res => {
					if (res.code == 1) {
						this.Mymedical = res.data.rows
						//console.log("this",this.Mymedical.length)
						if (this.Mymedical.length >= 1) {
							//console.log("进了")
							this.showlist = true
							//console.log(this.showlist)
						}
						uni.hideLoading();
						console.log(res)
					}
				})
			},
			successlist(itemsqb) {
				let item = {
					PatientId: itemsqb.PatientId,
					Name: itemsqb.Name
				}
				let items = JSON.stringify(item)
				uni.redirectTo({
					url: `/pages/project/project?items=${items}`,
					fail(error) {
						console.log(error)
					}
				})
			},
			showToast(params) {
				this.$refs.uToast.show({
					...params,
					complete() {
						params.url && uni.navigateTo({
							url: params.url
						})
					}
				})
			},
			confirm() {
				console.log(this.PatientId)
				uni.showLoading({
					title: '正在删除'
				})
				this.$request('TJChildBase', 'delete', {
					ChildId: this.PatientId
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						uni.hideLoading();
						//this.showToast(this.list)
						this.getlist()
					} else {
						uni.hideLoading();
						//this.showToast(this.list2)
					}
				})

				this.deleteshow = false
			},
			// xiugai(PatientId) {
			// 	console.log("PatientId", PatientId)
			// 	uni.navigateTo({
			// 		url: `/pages/block/addVisit/addVisitxg?PatientId=${PatientId}`,
			// 		fail(error) {
			// 			console.log(error)
			// 		}
			// 	})
			// 	// this.deleteshow = true
			// 	// this.PatientId = PatientId
			// 	// console.log(PatientId)
			// },
			deletes(TJChildId) {
				this.deleteshow = true
				this.PatientId = TJChildId
				console.log(TJChildId)

			},
			visit() {
				uni.redirectTo({
					url: `/pages/block/addVisit/addVisitcopy`,
					fail(error) {
						console.log(error)
					}
				})
			},
			addvisit() {
				this.show = true
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			}
		}
	}
</script>

<style>
	@import './Visit.css'
</style>
<style lang="scss">
	.u-page {
		padding: 0;
	}

	.u-cell-icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 8rpx;
	}

	.u-cell-group__title__text {
		font-weight: bold;
	}
</style>